<?php
/**
 * Created by PhpStorm.
 * User: denh
 * Date: 16/6/2
 * Time: 上午9:52
 */

class IndexController extends BaseController{

    function __construct($m, $a) {
        parent::__construct($m, $a);
    }

    function login() {
        if (!empty($_POST)) {
            $this->login_post();
        } else {
            require $this->template;
        }
    }

    function login_post() {
        $user = $this->request('user', '', true);
        $password = $this->request('password', '', true);
        $doUser = new Do后台管理员();
        $doUser->set_name($user);
        if (!$doUser->where($doUser->data)->count()) {
            $this->errorPage('用户名不存在！');
        }
        $doUser->set_pass(md5($password));
        if (!$doUser->where($doUser->data)->row()) {
            $this->errorPage('密码不正确！');
        }

        $_SESSION['user'] = $user;
        $_SESSION['id'] = $doUser->get_id();
        $this->redirect('system_config','index');
    }

    function loginOut() {
        unset($_SESSION['user']);
        unset($_SESSION['id']);
        $this->redirect('index', 'login');
    }
}